package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.TimeSlotRemainingCountDto;
import com.zzyl.nursing.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员预约信息相关接口
 * @author:
 * @date: 2020/5/19 17:09
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "会员预约信息相关接口")
public class MemberReservationController extends BaseController {

    @Autowired
    private IReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("获取会员预约取消数量")
    public AjaxResult getCancelledReservationCount() {
        int count = reservationService.countTodayCancelledReservations();
        return success(count);
    }

    /**
     * 获取每个时间段剩余预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation("获取每个时间段剩余预约次数")
    public AjaxResult getCountByTime(Long time){
        List<TimeSlotRemainingCountDto> counts = reservationService.getTimeSlotRemainingCounts(time);
        return success(counts);
    }

    /**
     * 新增预约信息
     * @return
     */
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult addReservation(@RequestBody Reservation  reservation) {
        reservationService.addReservation(reservation);
        return success();
    }

    /**
     * 分页查询预约信息
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约信息")
    public AjaxResult getReservationPage(@RequestBody Reservation reservation) {
        List<Reservation> reservations = reservationService.selectReservationList(reservation);
        return success(reservations);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancelReservation(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return success();
    }
}
